package com.test.hibernate;

import javax.servlet.ServletException;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

public class HibernatePlugin implements PlugIn {
	private String hibernateConfigFile;
	
	public void destroy() {
		System.out.println("-----in destroy()");
		//释放相关的资源 比如session factory
		SessionFactoryManager.closeSessionFactory();
	}
	public void setHibernateConfigFile(String hibernateConfigFile) {
		
		this.hibernateConfigFile = hibernateConfigFile;
	}
	public void init(ActionServlet arg0, ModuleConfig arg1)
			throws ServletException {
		System.out.println("-----plug  init hibernateConfigFile="+hibernateConfigFile);
		//1.读取hibernate 配置文件
		SessionFactoryManager.setHibernateConfigFile(hibernateConfigFile);
		//2.打开sessionfactory
		SessionFactoryManager.openSessionFactory();
		System.out.println("-----plug  初始化结束");
	}

}
